//  Copyright (c) 2020-present,  INSPUR Co, Ltd.  All rights reserved.
// This source code is licensed under Apache 2.0 License.

#pragma once

#include "pure_mem/memoryblock/memory_arena_index/memory_arena_art_index.h"
#include "pure_mem/memoryblock/memory_arena_index/memory_arena_index.h"
#include "pure_mem/memoryblock/memory_arena_index/memory_arena_vector_index.h"

namespace rocksdb {

enum MemArenaIndexType {
    ART = 1,
    VECTOR = 2
};

class MemoryBlock {
public:
    MemoryBlock(const InternalKeyComparator& mkeyCmp, MemArenaIndexType type) : type_(type){
        switch(type) {
            case ART:
                memory_arena_index = new MemArenaARTIndex(mkeyCmp);
                break;
            case VECTOR:
                memory_arena_index = new MemArenaVectorIndex();
                break;
            default:
                assert(0 == 1);
                break;
        }
    }

    ~MemoryBlock() {
      switch (type_){
        case ART:
          delete dynamic_cast<MemArenaARTIndex *>(memory_arena_index);
          break;
        case VECTOR:
          delete dynamic_cast<MemArenaVectorIndex *>(memory_arena_index);
          break;
        default:
          assert(0 == 1);
          break;
      }
    }

private:
    MemArenaIndexType type_;
    MemArenaIndex *memory_arena_index;
};

}